package com.sl.plugin.step.json;


import com.sl.core.engine.meta.impl.AbstractProcessCompDescriptor;
import com.sl.core.engine.step.ProcessCompService;
import com.sl.core.engine.step.impl.AbstractProcessComp;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 */
public class JsonGroupByComp extends AbstractProcessComp<List<Map<String, Object>>,  Map<Object, List<Map<String, Object>>>> implements ProcessCompService {


    public JsonGroupByComp(AbstractProcessCompDescriptor abstractProcessCompDescriptor) {
        super(abstractProcessCompDescriptor);
    }

    @Override
    public Map<Object, List<Map<String, Object>>> input(List<Map<String, Object>> param) {
        String fieldCode = meta.getStrAttr("fieldCode");
        Map<Object, List<Map<String, Object>>> collect = param.stream().collect(Collectors.groupingBy(v -> v.get(fieldCode)));
        return collect;

    }

}
